from app.repositories.user_repo import UserRepository


class AuthService:
    def __init__(self):
        self.user_repo = UserRepository()

    def register(self, name, email, password):
        if self.user_repo.find_by_email(email):
            return None
        return self.user_repo.create_user(name, email, password)

    def validate_credentials(self, email, password):
        from werkzeug.security import check_password_hash
        user = self.user_repo.find_by_email(email)
        if user and check_password_hash(user.password, password):
            return user
        return None